package com.test.controller;

import com.test.representation.UserContactRepresentation;
import com.test.representation.UserRepresentation;
import com.test.service.UserService;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by Jack on 6/30/2018.
 */
@RequiredArgsConstructor
@RestController
@RequestMapping("/users")
public class UserController {

  private final UserService userService;

  @GetMapping(path = "/{userId}")
  UserRepresentation getUserById(@PathVariable("userId") Long userId) {
    return userService.getUserByUserId(userId);
  }

  @GetMapping
  List<UserRepresentation> getUserByName(@RequestParam("name") String name) {
    return userService.getUserByName(name);
  }

  @GetMapping(path = "/{userId}/contacts")
  List<UserContactRepresentation> getContactsByUserId(@PathVariable("userId") Long userId) {
    return userService.getContactsByUserId(userId);
  }
}